﻿package net.wangit.dev.tree;

import net.wangit.context.ActionContext;
import net.wangit.dev.DomainAction;
import net.wangit.dev.ObjectChecker;
import net.wangit.jdbc.DB;
import net.wangit.util.Checker;
import net.wangit.view.tree.TreeCache;
import net.wangit.view.tree.TreeConfigCache;

public class DeleteTreeAction extends DomainAction {

	private static final String SQL_CHECK = "select l from TREECONFIG where tid=?";
	private static final String SQL_CONFIG = "delete from TREECONFIG where tid=?";
	private static final String SQL_ITEM = "delete from TREE where tid=?";

	public DeleteTreeAction() {
	}

	public void doAction(DB db, ActionContext ac) throws Exception {
		String treeId = ac.getRequestParameter("treeid");
		if (!Checker.isEmpty(treeId)) {
			net.wangit.MapList list = db.query(DeleteTreeAction.SQL_CHECK,
					treeId, 2);
			if (ObjectChecker.invalid(ac, list, "l"))
				return;
			db.execute(DeleteTreeAction.SQL_CONFIG, treeId, 2);
			db.execute(DeleteTreeAction.SQL_ITEM, treeId, 2);
			TreeCache.clear(domain, treeId);
			TreeConfigCache.clear(domain, treeId);
			TreeReferenceUtil.update(db, domain, treeId, "");
		}
	}
}
